﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Maticsoft.DBUtility;

namespace MedManager
{
    public partial class StockInList : Form
    {
        public StockInList()
        {
            InitializeComponent();
        }

        private void BindData()
        {
            StringBuilder sql = new StringBuilder("select a.id as '编号'");
            sql.Append(",a.medid as '药品编号'");
            sql.Append(",b.name as '药品名称'");
            sql.Append(",a.manufacturers as '厂家'");
            sql.Append(",a.pricein as '进货价格'");
            sql.Append(",a.amount as '进货总量'");
            sql.Append(",a.productiondate as '生产日期'");
            sql.Append(",a.shelflife as '保质期'");
            sql.Append(",case a.status when 0 then '未标记' when 1 then '标记过期' end as '过期标识'");
            sql.Append(",a.lastamount as '剩余库存'");
            sql.Append(",a.rowdate as '添加日期'");
            sql.Append(",c.username as '操作人'");
            sql.Append(" from stockin as a , medInfo as b , userinfo as c");
            sql.Append(" where a.medid=b.id and c.id=a.importer");
            if (!String.IsNullOrEmpty(txtDrugName.Text))
            {
                sql.Append(" and b.name like '%" + txtDrugName.Text.Trim() + "%'");
            }
            if (!String.IsNullOrEmpty(txtImporter.Text))
            {
                sql.Append(" and c.username like '%" + txtImporter.Text.Trim() + "%'");
            }
            sql.Append(" and a.rowdate between '" + dtpRowDateStart.Value + "' and '"+dtpRowDateEnd.Value+"'");
            DataTable dt = DbHelperSQL.Query(sql.ToString()).Tables[0];
            dgvStockInList.DataSource = dt;
        }

        private void InitControl()
        {
            dtpRowDateStart.Value = DateTime.Now.AddMonths(-1);
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            BindData();
        }

        private void StockInList_Load(object sender, EventArgs e)
        {
            this.Text = "入库信息";
            InitControl();
            BindData();
        }
    }
}
